package com.xiaoma.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 写数据
 */
public class NIOFileChannel01 {
    public static void main(String[] args) throws IOException {
        String  str = "hello xiaoma";
        FileOutputStream stream = new FileOutputStream("D:\\xiaoma.txt");
        FileChannel channel = stream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        buffer.put(str.getBytes());
        buffer.flip();
        channel.write(buffer);
        stream.close();
    }
}
